package com.sam.gui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.*;

import com.pingplusplus.android.PaymentActivity;
import com.sam.gui.base.BaseWebActivity;
import com.sam.ui.base.activity.BaseActivity;

/**
 * Created by Administrator on 2015-10-27.
 */
public class BespeakSpareTimeWebActivity extends BaseWebActivity {

    @Override
    protected void initView() {
        super.initView();
        setContentUrl("index.php?c=user&a=user_ap_view&ap_id="+getIntent().getExtras().getString("ap_id"));
    }

    @JavascriptInterface
    public void wzjlxq(){
        Intent intent = new Intent(this, DiagnosisRecordWebActivity.class);
        startActivity(intent);
    }

    @JavascriptInterface
    public void submitSuccess(){
        finish();
    }
    
     
    private final int REQUEST_CODE_PAYMENT = 168;
    
    @JavascriptInterface
    public void user_pay(String str){
    	
    	Intent intent = new Intent(this, PaymentActivity.class);
    	intent.putExtra(PaymentActivity.EXTRA_CHARGE, str);
    	startActivityForResult(intent, REQUEST_CODE_PAYMENT);

    }

    @JavascriptInterface
    public void comment_ap(String ap_id){
        Intent intent = new Intent(this, AppointmentEvaluationWebActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("ap_id", ap_id);
        intent.putExtras(bundle);
        startActivity(intent);
    }
    @JavascriptInterface
    public void ts_ap(String ap_id){
        Intent intent = new Intent(this, ComplaintAppointmentWebActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("ap_id", ap_id);
        intent.putExtras(bundle);
        startActivity(intent);
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        //支付页面返回处理
       if (requestCode == REQUEST_CODE_PAYMENT) {
           if (resultCode == Activity.RESULT_OK) {
               String result = data.getExtras().getString("pay_result");
               /* 处理返回值
                * "success" - 支付成功
                * "fail"    - 支付失败
                * "cancel"  - 取消支付
                * "invalid" - 支付插件未安装（一般是微信客户端未安装的情况）
                */
               
               String errorMsg = data.getExtras().getString("error_msg"); // 错误信息
               String extraMsg = data.getExtras().getString("extra_msg"); // 错误信息

               assert result != null;
               if(result.equals("success")){
            	   alert("支付成功!");
                   reload();
                   finish();
               }
               if(result.equals("cancel")){
                   alert("你已取消支付!");
               }
               if(result.equals("fail")){
                   alert("支付失败,错误信息:"+errorMsg);
                   reload();
               }
           }
       }
   }
}
